package com.mock.action.geography.trustregion;

import java.util.ArrayList;
import java.util.List;

import com.mock.dao.CountryDao;
import com.mock.dao.TrustRegionDao;
import com.mock.dao.impl.CountryDaoImpl;
import com.mock.dao.impl.TrustRegionDaoImp;
import com.mock.model.Country;
import com.mock.model.TrustRegion;
import com.opensymphony.xwork2.ActionSupport;

public class EditTrustRegionAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		trustRegion = trustRegionDao.getById(trustRegionId);
		generateData();
		return SUCCESS;
	}
	
	public String update() throws Exception {
		TrustRegion trustRegion1 = trustRegionDao.getById(trustRegionId);
		trustRegion1.setCountry(countryDao.getById(country));
		trustRegion1.setDescription(trustRegionDescription);
		trustRegion1.setName(trustRegionName);
		trustRegionDao.update(trustRegion1);
		return SUCCESS;
	}
	
	public String markInActive() throws Exception {		
		TrustRegion trustRegion2 = trustRegionDao.getById(trustRegionId);
		trustRegion2.setActive(false);
		trustRegionDao.update(trustRegion2);
		return SUCCESS;
	}
	
	public void generateData() {
		countries = countryDao.getAllCountry();
	}
	
	private long trustRegionId = -1L;
	private List<Country> countries = new ArrayList<Country>();		
	private CountryDao countryDao = new CountryDaoImpl();
	private TrustRegionDao trustRegionDao = new TrustRegionDaoImp();
	
	private TrustRegion trustRegion;
	private Long country;
	private String trustRegionName;
	private String trustRegionDescription;

	public long getTrustRegionId() {
		return trustRegionId;
	}

	public void setTrustRegionId(long trustRegionId) {
		this.trustRegionId = trustRegionId;
	}

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}

	public TrustRegion getTrustRegion() {
		return trustRegion;
	}

	public void setTrustRegion(TrustRegion trustRegion) {
		this.trustRegion = trustRegion;
	}

	public Long getCountry() {
		return country;
	}

	public void setCountry(Long country) {
		this.country = country;
	}

	public String getTrustRegionName() {
		return trustRegionName;
	}

	public void setTrustRegionName(String trustRegionName) {
		this.trustRegionName = trustRegionName;
	}

	public String getTrustRegionDescription() {
		return trustRegionDescription;
	}

	public void setTrustRegionDescription(String trustRegionDescription) {
		this.trustRegionDescription = trustRegionDescription;
	}
	
}
